﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ReferArrayOfDecimals", Namespace="http://kis.x-road.eu/", Target=typeof(ReferArrayOfDecimals))]
    public class ReferArrayOfDecimalsSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ReferArrayOfDecimals clazz;
        
        public ReferArrayOfDecimalsSerializer(ReferArrayOfDecimals clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ReferedArrayComplexType");
            if (clazz.ReferedArrayComplexType!=null) {
                for (int x = 0; ((clazz.ReferedArrayComplexType != null) 
                            && (x < clazz.ReferedArrayComplexType.Count)); x = (x + 1)) {
                    if (clazz.ReferedArrayComplexType[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.ReferedArrayComplexType[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ReferedArrayComplexType");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ReferedArrayComplexType") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ReferArrayOfDecimals>ReferedArrayComplexType");
                }
                clazz.ReferedArrayComplexType = new System.Collections.Generic.List<System.Decimal?>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ReferedArrayComplexType");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if ((Reader.IsElementNil() == false)) {
                            clazz.ReferedArrayComplexType.Add(new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("item")).Value);
                        }
                        else {
                            clazz.ReferedArrayComplexType.Add(null);
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ReferArrayOfDecimals>ReferedArrayComplexType", Reader.LocalName);
            }
        }
    }
}
